<?php
/**
 * 会员操作日志记录管理
 *
 * @version        $Id: member_operations.php 1 11:24 2010年7月20日Z tianya $
 * @package        DedeBIZ.Administrator
 * @copyright      Copyright (c) 2022, DedeBIZ.COM
 * @license        https://www.dedebiz.com/license
 * @link           https://www.dedebiz.com
 */
require_once(dirname(__FILE__)."/config.php");
CheckPurview('member_Operations');
setcookie("ENV_GOBACK_URL",$dedeNowurl,time()+3600,"/");
require_once(DEDEINC.'/datalistcp.class.php');
if(empty($buyid)) $buyid = '';
$addsql = " WHERE buyid LIKE '%$buyid%' ";
if(isset($sta)) $addsql .= " AND sta='$sta' ";
$sql = "SELECT * FROM `#@__member_operation` $addsql ORDER BY aid DESC";
$dlist = new DataListCP();
$thismonth_start=mktime(0,0,0,date('m'),1,date('Y')); //本月开始
$thismonth_end=mktime(23,59,59,date('m'),date('t'),date('Y'));//本月结束
$m = date('Y-m-d', mktime(0,0,0,date('m')-1,1,date('Y'))); //上个月的开始日期
$t = date('t',strtotime($m)); //上个月共多少天
$sstart = mktime(0,0,0,date('m')-1,1,date('Y')); //上个月的开始日期
$send =  mktime(23,59,59,date('m')-1,$t,date('Y')); //上个月的结束日期  {dede:global.allm/}
$nowsql = "SELECT COUNT(aid) as num,sum(money) as allm FROM `#@__member_operation` where mtime > $thismonth_start and mtime < $thismonth_end and sta=2";
$temp = $dsql->GetOne($nowsql);
if($temp['allm'] == null){$temp['allm']=0;}
$nowc=$temp['num'];
$allm=$temp['allm'];
$oldspl = "SELECT COUNT(aid) as num,sum(money) as allm FROM `#@__member_operation` where mtime > $sstart and mtime < $send and sta=2";
$oldtemp = $dsql->GetOne($oldspl);
if($oldtemp['allm'] == null){$oldtemp['allm']=0;}
$oldc=$oldtemp['num'];
$oldm=$oldtemp['allm'];
$allspl = "SELECT sum(money) as allm FROM `#@__member_operation` where sta=2";
$alltemp = $dsql->GetOne($allspl);
if($alltemp['allm'] == null){$alltemp['allm']=0;}
$all_m=$alltemp['allm'];
//设定每页显示记录数（默认30条）
$dlist->pageSize = 30;
$dlist->SetParameter("buyid",$buyid);
if(isset($sta)) $dlist->SetParameter("sta",$sta);
$dlist->dsql->SetQuery("SELECT * FROM #@__moneycard_type ");
$dlist->dsql->Execute('ts');
while($rw = $dlist->dsql->GetArray('ts'))
{
$TypeNames[$rw['tid']] = $rw['pname'];
}
$tplfile = DEDEADMIN."/templets/member_operations.htm";
//这两句的顺序不能更换
$dlist->SetTemplate($tplfile);      //载入模板
$dlist->SetSource($sql);            //设定查询SQL
$dlist->Display();                  //显示
function GetMemberID($mid)
{
    global $dsql;
    if($mid==0)
    {
        return '0';
    }
    $row = $dsql->GetOne("SELECT userid FROM #@__member WHERE mid='$mid' ");
    if(is_array($row))
    {
        return "<a href='member_view.php?id={$mid}'>".$row['userid']."</a>";
    }
    else
    {
        return '0';
    }
}
function GetPType($tname)
{
    if($tname=='card') return '点数卡';
    else if($tname=='archive') return '购买文章';
    else if($tname=='stc') return '兑换金币';
    else return 'SVIP会员';
}
function GetSta($sta)
{
    if($sta==0)
    {
        return '未付款';
    }
    else if($sta==1)
    {
        return '已完成';
    }
    else
    {
        return '已完成';
    }
}